#include "dialog.h"
#include <QPainter>
#include <QTimer>

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
{
    angle = 0;

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    timer->start(1000);
}

Dialog::~Dialog()
{

}

void Dialog::paintEvent(QPaintEvent *event)
{
    // 时钟
    angle += 10;
    if (angle == 360)
    {
        angle = 0;
    }

    int side = qMin(width(), height());
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    QTransform transform;
    transform.translate(width() / 2, height() / 2);
    transform.scale(side / 300.0, side / 300.0);
    transform.rotate(angle);
    painter.setWorldTransform(transform);

    painter.drawEllipse(-120, -120, 240, 240);
    painter.drawLine(0, 0, 100, 0);
}
